﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Common;
using DataAccess;

public partial class Manager_EditProfileManager : System.Web.UI.Page
{
    DataTable table;
    string ManagerID = "";
    protected void Page_Init(object sender, EventArgs e)
    {
        if (Session["ManagerID"] != "")
        {
            ManagerID = Request.QueryString["ID"];
            DbCommand cmd = GenericData.CreateCommand();
            cmd.CommandText = "SELECT * FROM Manager WHERE ID = " + ManagerID;
            table = GenericData.ExecuteReader(cmd);
            if (table.Rows.Count > 0)
            {
                txtUsername.Text = table.Rows[0]["Username"].ToString();
                txtEmail.Text = table.Rows[0]["Email"].ToString();
                txtFullname.Text = table.Rows[0]["Fullname"].ToString();
                txtMobile.Text = table.Rows[0]["Mobile"].ToString();
                txtAddress.Text = table.Rows[0]["Address"].ToString();
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        //get data from form
        string Email = txtEmail.Text;
        string Fullname = txtFullname.Text;
        string Mobile = txtMobile.Text;
        string Address = txtAddress.Text;

        Manager mng = new Manager();
        mng.Email = Email;
        mng.Address = Address;
        mng.ID = int.Parse( ManagerID);
        mng.Mobile = Mobile;
        mng.Fullname = Fullname;

        UpdateManager updateManager = new UpdateManager();
       
        if (updateManager.Update(mng))
            Session.Add("Message", "Update profile successfully");
        else
            Session.Add("Message", "<font color='red'>Error : Update profile unsuccess</font>");

        Response.Redirect("Profile.aspx");
    }
}